package com.power.services.user;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.power.dao.user.SysuserDAO;
import com.power.model.user.TsSysuser;

@Service("sysuserService")
public class SysuserServiceImpl implements SysuserService {

	@Autowired
	private SysuserDAO dao;

	public void create(TsSysuser arg0) {
		dao.save(arg0);
	}

	public void delete(TsSysuser arg0) {
		dao.delete(arg0);
	}

	public TsSysuser read(Integer arg0) {
		return dao.get(arg0);
	}

	public void update(TsSysuser arg0) {
		dao.update(arg0);
	}

	@SuppressWarnings("unchecked")
	public List<TsSysuser> findByLogonnameWithDate(String type,String logonname) {
		String hql = "select d from com.power.model.user.TsSysuser d  where d.username='"
						+ logonname + "'";
		if(!"".equals(type))
			hql+=" and d.category='"+type+"'" ;
		return dao.find(hql);
	}

	public void updatePassword(TsSysuser user) {
		dao.executeSql("UPDATE t_s_sysuser SET PASSWORD='" + user.getPassword()
				+ "' WHERE id=" + user.getId());
	}

	@SuppressWarnings("unchecked")
	public List<TsSysuser> findByLogonnameAndPassword(TsSysuser tsSysuser) {
		return dao
				.find("select d from com.power.model.user.TsSysuser d  where  d.username='"
						+ tsSysuser.getUsername()
						+ "'"
						+ " and d.password ='"
						+ tsSysuser.getPassword() + "'");
	}
}
